<?php
header('content-type:text/html; charset=utf-8');
@$login=$_REQUEST['login'];
@$password=$_REQUEST['password'];
@$code = $_REQUEST['code'];

session_start();

require  'lib/code.php';

if (!checkCode($code)){
	$mes = '验证码错误，请重新填写！';
	include 'index.php';
	die;
}

if(empty($login)||empty($password)||empty($code)){
	$mes="登录名,密码,验证码必须填写！";
	include "index.php";
	die;
}
require 'lib/db.php';
@$user = dbSelect('select id,password from users where login=:login',array('login'=>$login));

if(empty($user)){
	$mes="登录名不存在，请重新填写！";
	include "index.php";
	die;
}
if($user['password']!=$password){
	$mes="密码错误，请重新登录！";
	include "index.php";
	die;
}
$_SESSION['userId']=$user['id'];

header('Refresh:0;url=/First.php');